package com.jonathan.currentlimiting.controller;

import com.google.common.util.concurrent.RateLimiter;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *@ClassName GuavaLimiting
 *@Description TODO
 *@Author wangl
 *@Date 2022/03/28
 */
@RestController
public class GuavaLimiting {
    RateLimiter rateLimiter = RateLimiter.create(1);

    @RequestMapping("/GuavaLimiting")
    public String get() {
        Double b = rateLimiter.acquire();

        System.out.println(b);
        if (b <= 0) {
            return "hello";
        } else {
            return "限流重试";
        }

    }
}
